package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class GenericDemo {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();
        c.add("1");
        c.add("2");
        c.add("3");
        c.add("4");
        c.add("5");
        Iterator<String> it = c.iterator();
        while (it.hasNext()){
            String str = it.next();
            System.out.println(str);
        }

        for (String str:c){
            System.out.println(str);
        }

        Collection<Point> cp = new ArrayList<>();
        cp.add(new Point(1,2));
        cp.add(new Point(3,4));
        cp.add(new Point(5,6));
        cp.add(new Point(7,8));
        Iterator<Point> ite = cp.iterator();
        while (ite.hasNext()){
            Point point = ite.next();
            System.out.println(point);
        }
        for (Point point: cp){
            System.out.println(point);
        }
    }
}
